package hu.genius.view;

import hu.genius.R;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class PizzaMenuListActivity extends ListActivity implements OnClickListener {

	private String[] pizzaMenuItems;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sub_menulist_layout);

		pizzaMenuItems = new String[] { getString(R.string.pizza_sweet_label),
				getString(R.string.pizza_stuffed_label),
				getString(R.string.pizza_tomato_base_label),
				getString(R.string.pizza_vega_label),
				getString(R.string.pizza_barbecue_base_label),
				getString(R.string.pizza_garlic_sour_label) };
		
		Button backButton = (Button) findViewById(R.id.subMenuBackButton);
		backButton.setOnClickListener(this);
		
		TextView menuLabelTextView = (TextView) findViewById(R.id.subMenuLabelTextView);
		menuLabelTextView.setText(getString(R.string.pizza_menu_label));
		
		this.setListAdapter(new ArrayAdapter<String>(this,
				R.layout.list_black_text, R.id.list_content, pizzaMenuItems));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		Intent intent = new Intent(PizzaMenuListActivity.this, ProductsListActivity.class);
		intent.putExtra("category_name", pizzaMenuItems[position]);
		intent.putExtra("products_label", getString(R.string.pizza_menu_label));

		switch (position) {
		case 0:
			intent.putExtra("category_id", 12);
			break;
		case 1:
			intent.putExtra("category_id", 14);
			break;
		case 2:
			intent.putExtra("category_id", 29);
			break;
		case 3:
			intent.putExtra("category_id", 15);
			break;
		case 4:
			intent.putExtra("category_id", 30);
			break;
		case 5:
			intent.putExtra("category_id", 31);
			break;
		}
		PizzaMenuListActivity.this.startActivity(intent);
	}

	public void onClick(View v) {
		if (v != null && v.getId() == R.id.subMenuBackButton) {
			this.finish();
		}
	}
	
}
